---@class T_buffBean
local t_buffBean = ClientFight.CreateClass("T_buffBean")
function t_buffBean:ctor()
    --/** buffID */
    --@TplAttr(name = "f_BuffId")
    self.f_BuffId = 0

    --/** buff描述 */
    --@TplAttr(name = "f_BuffName")
    self.f_BuffName = ""

    --/** BUFF类型 */
    --@TplAttr(name = "f_BuffType")
    self.f_BuffType = 0

    --/** BUFF添加条件 */
    ---@type number[][]
    self.f_BuffAddCondition = nil

    --/** 是否控制效果 */
    --@TplAttr(name = "f_Control")
    ---@type number[]
    self.f_Control = nil

    --/** BUFF标记 */
    --@TplAttr(name = "f_Tag")
    ---@type number[]
    self.f_Tag = nil

    --/** 互斥BUFF标记 */
    --@TplAttr(name = "f_Exclusion")
    ---@type number[]
    self.f_Exclusion = nil

    --/** BUFF触发时机 */
    --@TplAttr(name = "f_BuffActionTrigger")
    self.f_BuffActionTrigger = 0

    --/** BUFF移除时机 */
    --@TplAttr(name = "f_BuffRemoveTrigger")
    self.f_BuffRemoveTrigger = 0

    --/** 触发参数 */
    --@TplAttr(name = "f_BuffTrigger")
    ---@type number[]
    self.f_BuffTrigger = nil

    --/** BUFF移除参数 */
    --@TplAttr(name = "f_BuffRemoveParameter")
    ---@type number[]
    self.f_BuffRemoveParameter = nil

    --/** BUFF移除条件 */
    ---@type number[][]
    self.buffRemoveCondition = nil

    --/** 目标指向 */
    --@TplAttr(name = "f_Target")
    self.f_Target = 0

    --/** BUFF触发概率万分比 */
    self.f_BuffProbability = 0

    --/** 触发优先级 */
    --@TplAttr(name = "f_Priority")
    self.f_Priority = 0

    --/** BUFF持续时间（毫秒） */
    self.f_BuffRound = 0

    --/** BUFF间隔时间（BUFF持续时间内，间隔触发） */
    self.f_BuffTime = 0

    --/** BUFF加上时附加属性值 */
    ---@type number[][]
    self.f_Atribute = nil

    --/** BUFF触发时增加其他BUFF信息 */
    ---@type number[][]
    self.f_AddBuff = nil
    --/** BUFF移除时,添加其他buff */

    --@TplAttr(name = "f_RemoveBuffAdd")
    ---@type number[][]
    self.f_RemoveBuffAdd = nil

    --/** buff特殊效果 */
    --@TplAttr(name = "f_BuffSpecialEffect")
    ---@type number[]
    self.f_BuffSpecialEffect = nil

    --/** BUFF效果 */
    --@TplAttr(name = "f_BuffEffect")

    self.f_BuffEffect = 0

    --/** BUFF触发条件 */
    ---@type number[][]
    self.f_BuffCondition = nil

    --/** BUFF效果值（用于输入BUFF效果参数） */
    ---@type number[]
    self.f_BuffEffectValueTemp = nil

    ---@type number[]
    self.f_BuffEffectValue = nil

    --/** 全局buff */
    --@TplAttr(name = "f_BuffAll")
    self.f_BuffAll = 0

    --/** 替换规则 */
    --@TplAttr(name = "f_Replace")
    self.f_Replace = 0

    --/** 替换层级 */
    --@TplAttr(name = "f_RepalceLyer")
    self.f_RepalceLyer = 0

    --/** 替换优先级 */
    --@TplAttr(name = "f_RepalcePriority")
    self.f_RepalcePriority = 0

    --/** 叠加最大层数 */
    --@TplAttr(name = "f_MaxReplaceLyer")
    self.f_MaxReplaceLyer = 0

    --@TplAttr(name = "f_BuffAddCondition")
    self.f_BuffAddCondition1 = ""
    ---@type number[]
    self.f_BuffAddCondition1Dynamicparam = nil----懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffRemoveCondition")
    self.buffRemoveCondition1 = ""
    ---@type number[]
    self.buffRemoveCondition1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffProbability")
    self.f_BuffProbability1 = ""
    ---@type number[]
    self.f_BuffProbability1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffRound")
    self.f_BuffRound1 = ""
    ---@type number[]
    self.f_BuffRound1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffTime")
    self.f_BuffTime1 = ""
    ---@type number[]
    self.f_BuffTime1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_Atribute")
    self.f_Atribute1 = ""
    ---@type number[]
    self.f_Atribute1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_AddBuff")
    self.f_AddBuff1 = ""
    ---@type number[]
    self.f_AddBuff1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffCondition")
    self.f_BuffCondition1 = ""
    ---@type number[]
    self.f_BuffCondition1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容

    --@TplAttr(name = "f_BuffEffectValue")
    self.f_BuffEffectValue1 = ""
    ---@type number[]
    self.f_BuffEffectValue1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    --这个buff包含动态参数
    self.dynamicParamBuff = false
end
function t_buffBean:loadCfg(cfg)
    self.f_BuffId = cfg.f_BuffId
    self.f_BuffName = cfg.f_BuffName
    self.f_BuffType = cfg.f_BuffType
    self.f_BuffAddCondition = nil
    self.f_Control = decodeJsonStrToTabel(cfg.f_Control)
    self.f_Tag = decodeJsonStrToTabel(cfg.f_Tag)
    self.f_Exclusion = decodeJsonStrToTabel(cfg.f_Exclusion)
    self.f_BuffActionTrigger = cfg.f_BuffActionTrigger
    self.f_BuffRemoveTrigger = cfg.f_BuffRemoveTrigger
    self.f_BuffTrigger = decodeJsonStrToTabel(cfg.f_BuffTrigger)
    self.f_BuffRemoveParameter = decodeJsonStrToTabel(cfg.f_BuffRemoveParameter)
    self.buffRemoveCondition = nil
    --@TplAttr(name = "f_Target")
    self.f_Target = cfg.f_Target
    self.f_BuffProbability = 0
    self.f_Priority = cfg.f_Priority
    self.f_BuffRound = 0
    self.f_BuffTime = 0
    self.f_Atribute = nil

    self.f_AddBuff = nil
    self.f_RemoveBuffAdd = decodeJsonStrToTabel(cfg.f_RemoveBuffAdd)
    if cfg.f_BuffSpecialEffect~= "" then
        self.f_BuffSpecialEffect = cfg.f_BuffSpecialEffect
    end
    self.f_BuffEffect = cfg.f_BuffEffect
    self.f_BuffCondition = nil
    self.f_BuffEffectValueTemp = nil
    self.f_BuffEffectValue = nil
    self.f_BuffAll = cfg.f_BuffAll
    self.f_Replace = cfg.f_Replace
    self.f_RepalceLyer = cfg.f_RepalceLyer
    self.f_RepalcePriority = cfg.f_RepalcePriority
    self.f_MaxReplaceLyer = cfg.f_MaxReplaceLyer
    self.f_BuffAddCondition1 = cfg.f_BuffAddCondition
    self.f_BuffAddCondition1Dynamicparam = nil----懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.buffRemoveCondition1 = cfg.f_BuffRemoveCondition
    self.buffRemoveCondition1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_BuffProbability1 = cfg.f_BuffProbability
    self.f_BuffProbability1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_BuffRound1 = cfg.f_BuffRound
    self.f_BuffRound1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_BuffTime1 = cfg.f_BuffTime
    self.f_BuffTime1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_Atribute1 = cfg.f_Atribute
    self.f_Atribute1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_AddBuff1 = cfg.f_AddBuff
    self.f_AddBuff1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_BuffCondition1 = cfg.f_BuffCondition
    self.f_BuffCondition1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.f_BuffEffectValue1 = cfg.f_BuffEffectValue
    self.f_BuffEffectValue1Dynamicparam = nil--懒得用反射封装了, 直接简单粗暴点存储预加载内容
    self.dynamicParamBuff = false
end
---做点预加载的事情
function t_buffBean:afterLoadBuff()
    if string.IsEmpty(self.f_AddBuff) and self.f_BuffEffect < 1 then
        self.f_BuffActionTrigger = 0
    end
    --懒得用反射封装了, 直接简单粗暴点做预加载内容, 以后要是有新增的字段里也带动态参数, 自己新增这个字段的解析就行了
    if not self:containsDynamic(self.f_BuffAddCondition1) then
        self.f_BuffAddCondition = decodeJsonStrToTabel(self.f_BuffAddCondition1)
    else
        self.f_BuffAddCondition1Dynamicparam = self:analysisDynamicName(self.f_BuffAddCondition1)
    end
    if (not self:containsDynamic(self.buffRemoveCondition1)) then
        self.buffRemoveCondition = decodeJsonStrToTabel(self.buffRemoveCondition1);
    else
        self.uffRemoveCondition1Dynamicparam = self:analysisDynamicName(self.buffRemoveCondition1);
    end
    if (not self:containsDynamic(self.f_BuffProbability1)) then
        if (not string.IsEmpty(self.f_BuffProbability1)) then
            self.f_BuffProbability = tonumber(self.f_BuffProbability1);
        end
    else
        self.f_BuffProbability1Dynamicparam = self:analysisDynamicName(self.f_BuffProbability1);
    end
    if (not self:containsDynamic(self.f_BuffRound1)) then
        if self.f_BuffRound1 ~= "" then
            self.f_BuffRound = tonumber(self.f_BuffRound1);
        end
    else
        self.f_BuffRound1Dynamicparam = self:analysisDynamicName(self.f_BuffRound1);
    end
    if (not self:containsDynamic(self.f_BuffTime1)) then
        if (not string.IsEmpty(self.f_BuffTime1)) then
            self.f_BuffTime = tonumber(self.f_BuffTime1);
        end
    else
        self.f_BuffTime1Dynamicparam = self:analysisDynamicName(self.f_BuffTime1);
    end
    if (not self:containsDynamic(self.f_Atribute1)) then
        self.f_Atribute = decodeJsonStrToTabel(self.f_Atribute1);
    else
        self.f_Atribute1Dynamicparam = self:analysisDynamicName(self.f_Atribute1);
    end
    if (not self:containsDynamic(self.f_AddBuff1)) then
        self.f_AddBuff = decodeJsonStrToTabel(self.f_AddBuff1);
    else
        self.f_AddBuff1Dynamicparam = self:analysisDynamicName(self.f_AddBuff1);
    end
    if (not self:containsDynamic(self.f_BuffCondition1)) then
        self.f_BuffCondition = decodeJsonStrToTabel(self.f_BuffCondition1);
    else
        self.f_BuffCondition1Dynamicparam = self:analysisDynamicName(self.f_BuffCondition1);
    end
    if (not self:containsDynamic(self.f_BuffEffectValue1)) then
        self.f_BuffEffectValueTemp = decodeJsonStrToTabel(self.f_BuffEffectValue1);
    else
        self.f_BuffEffectValue1Dynamicparam = self:analysisDynamicName(self.f_BuffEffectValue1);
    end
    self:getF_BuffEffectValue()
end

function t_buffBean:analysisDynamicName(fieldValue)
    self.dynamicParamBuff = true
    local values = DynamicParam.valueNames()
    local list = {}
    for k,v in pairs(values) do
        if string.Contains(fieldValue,v) then
            table.insert(list,v)
        end
    end
    return list
end
function t_buffBean:containsDynamic(fieldValue)
    if string.IsEmpty(fieldValue) or type(fieldValue) == "table" then return false end
    local values = DynamicParam.valueNames()
    for k,v in pairs(values) do
        if string.Contains(fieldValue,v) then
            return true
        end
    end
    return false
end
function t_buffBean:cloneInstance()
    return clone(self)
end
---用 角色的数据 去动态替换掉 buff的动态参数
---@param fighter Fighter
function t_buffBean:dynamicParamParse(fighter)
    local dynamicParamMap = fighter.buffDynamicParam[self.f_BuffId]
    if dynamicParamMap == nil then
        SkillRoleMgr.savePathFile("[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                .. "解析动态参数字段:失败, 英雄携带的参数列表为空 ");
        return false
    end
    if table.getn(self.f_BuffAddCondition1Dynamicparam) then
        for k,dynamicParam in pairs(self.f_BuffAddCondition1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if value == nil then
                SkillRoleMgr.savePathFile("[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                       .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:buffRemoveCondition1 = "..f_BuffAddCondition1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false
            end
            self.f_BuffAddCondition1 = string.gsub(self.f_BuffAddCondition1,DynamicParam.nameOf(dynamicParam),value)
        end
    end
    if not string.IsEmpty(self.buffRemoveCondition1Dynamicparam) then
        for k,dynamicParam in pairs(self.buffRemoveCondition1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if value == nil then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:buffRemoveCondition1= "..buffRemoveCondition1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false
            end
            self.buffRemoveCondition1 = table.gsub( self.buffRemoveCondition1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.buffRemoveCondition = decodeJsonStrToTabel(self.buffRemoveCondition1)
    end
    if not string.IsEmpty(self.f_BuffProbability1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_BuffProbability1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                .. "解析动态参数字段:f_BuffProbability1= "..f_BuffProbability1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false
            end
            self.f_BuffProbability1 = table.gsub( self.f_BuffProbability1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_BuffProbability = tonumber(self.f_BuffProbability1)
    end
    if not string.IsEmpty(self.f_BuffRound1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_BuffRound1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_BuffRound1 = table.gsub( self.f_BuffRound1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_BuffRound = tonumber(self.f_BuffRound1);
    end
    if not string.IsEmpty(self.f_BuffTime1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_BuffTime1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile("[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_BuffTime1 = table.gsub( self.f_BuffTime1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_BuffTime = tonumber(self.f_BuffTime1);
    end
    if not string.IsEmpty(self.f_Atribute1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_Atribute1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_Atribute1 = table.gsub( self.f_Atribute1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_Atribute = tonumber(self.f_Atribute1);
    end
    if not string.IsEmpty(self.f_AddBuff1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_Atribute1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_AddBuff1 = table.gsub( self.f_AddBuff1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_AddBuff = decodeJsonStrToTabel(self.f_AddBuff1);
    end
    if not string.IsEmpty(self.f_BuffCondition1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_BuffCondition1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_BuffCondition1 = table.gsub( self.f_BuffCondition1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_BuffCondition = decodeJsonStrToTabel(self.f_BuffCondition1);
    end
    if not string.IsEmpty(self.f_BuffEffectValue1Dynamicparam) then
        for k, dynamicParam in pairs(self.f_BuffEffectValue1Dynamicparam) do
            local value = dynamicParamMap[dynamicParam]
            if (value == nil) then
                SkillRoleMgr.savePathFile( "[" .. fighter.fight.frame .. "][BUFF]" .. f_BuffId
                        .."[Fighter]:"..fighter.fighterId.." 英雄id:"..fighter.modelId
                        .. "解析动态参数字段:f_BuffRound1= "..f_BuffRound1.." 失败, 英雄携带的参数列表: "..getJsonStr(dynamicParamMap));
                return false;
            end
            self.f_BuffEffectValue1 = table.gsub( self.f_BuffEffectValue1,DynamicParam.nameOf(dynamicParam),value)
        end
        self.f_BuffEffectValueTemp = decodeJsonStrToTabel(self.f_BuffEffectValue1);
    end
    self:getF_BuffEffectValue()
    return true
end
---@return number[]
function t_buffBean:getF_BuffEffectValue()
    if self.f_BuffEffectValue == nil and self.f_BuffEffectValueTemp then
        local intArr = {}
        for k,v in pairs(self.f_BuffEffectValueTemp) do
            table.insert(intArr,v)
        end
        self.f_BuffEffectValue = intArr
    end
    return self.f_BuffEffectValue
    --[[if self.f_BuffEffectValueTemp == nil then
        return nil
    end
    if self.f_BuffEffectValueIntValue ~= nil then
        return self.f_BuffEffectValueIntValue
    end
    local intArr = {}
    for k,v in pairs(self.f_BuffEffectValueTemp) do
        table.insert(intArr,v)
    end
    self.f_BuffEffectValueIntValue = intArr
    return intArr]]
end